package com.example.hxds.workflow.controller;
import cn.hutool.core.bean.BeanUtil;
import com.example.hxds.common.util.R;
import com.example.hxds.workflow.controller.form.AcceptCommentAppealForm;
import com.example.hxds.workflow.controller.form.HandleCommentAppealForm;
import com.example.hxds.workflow.controller.form.SearchAppealContentForm;
import com.example.hxds.workflow.controller.form.StartCommentWorkflowForm;
import com.example.hxds.workflow.service.OrderCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.HashMap;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Author XUYANG
 * @Date 2024-04-10 15:31
 */
@RestController
@RequestMapping("/comment")
public class OrderCommentController {
    @Resource
    private OrderCommentService orderCommentService;

    @PostMapping("/handleCommentAppeal")
    public R handleCommentAppeal(@RequestBody @Valid HandleCommentAppealForm handleCommentAppealForm) {
        this.orderCommentService.handleCommentAppeal(BeanUtil.beanToMap(handleCommentAppealForm));
        return R.ok();
    }

    @PostMapping("/acceptCommentAppeal")
    public R acceptCommentAppeal(@RequestBody @Valid AcceptCommentAppealForm acceptCommentAppealForm) {
        this.orderCommentService.acceptCommentAppeal(BeanUtil.beanToMap(acceptCommentAppealForm));
        return R.ok();
    }

    @PostMapping({"/searchAppealContent"})
        public R searchAppealContent(@RequestBody @Valid SearchAppealContentForm searchAppealContentForm) {
        return R.ok().put("result", this.orderCommentService.searchAppealContent(searchAppealContentForm.getInstanceId(), searchAppealContentForm.getIsEnd().booleanValue()));
    }

    @PostMapping({"/startCommentWorkflow"})
    public R startCommentWorkflow(@RequestBody @Valid StartCommentWorkflowForm startCommentWorkflowForm) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("orderId", startCommentWorkflowForm.getOrderId().toString());
        hashMap.put("driverId", startCommentWorkflowForm.getDriverId().toString());
        hashMap.put("customerId", startCommentWorkflowForm.getCustomerId().toString());
        hashMap.put("reason", startCommentWorkflowForm.getReason());
        this.orderCommentService.startCommentWorkflow(hashMap);
        return R.ok();
    }
}
